﻿using DynamicPatcher;
using PatcherYRpp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Extension.Ext
{
    public partial class TechnoExt
    {
        public unsafe void TechnoClass_Debug_OnInit()
        {
           
        }

        public unsafe void TechnoClass_Debug_OnUpdate()
        {
           
        }

        public unsafe void TechnoClass_Debug_OnPut(CoordStruct coordStruct, Direction faceDir)
        {
            Logger.Log($"{OwnerObject.Ref.Type.Ref.Base.Base.ID}被放置在({coordStruct.X},{coordStruct.Y},{coordStruct.Z}),朝向{faceDir}");
        }

        public unsafe void TechnoClass_Debug_OnFire(Pointer<AbstractClass> pTarget, int weaponIndex)
        {
            string name = string.Empty;
            if(pTarget.CastToTechno(out var ptechno))
            {
                name = ptechno.Ref.Type.Ref.Base.Base.ID;
            }
            Logger.Log($"{OwnerObject.Ref.Type.Ref.Base.Base.ID}使用武器{weaponIndex}向{pTarget.Ref.WhatAmI()}:{name}开火");
        }

        public unsafe void TechnoClass_Debug_OnReceiveDamage(Pointer<int> pDamage, int DistanceFromEpicenter, Pointer<WarheadTypeClass> pWH,
         Pointer<ObjectClass> pAttacker, bool IgnoreDefenses, bool PreventPassengerEscape, Pointer<HouseClass> pAttackingHouse)
        {
            string attacker = string.Empty;
            if(!pAttacker.IsNull)
            {
                if (pAttacker.CastToTechno(out var ptechno))
                {
                    attacker = ptechno.Ref.Type.Ref.Base.Base.ID;
                }
            }

            Logger.Log($"{OwnerObject.Ref.Type.Ref.Base.Base.ID}受到来自{attacker}的伤害,伤害值{pDamage.Ref},弹头{pWH.Ref.Base.ID},当前生命值{OwnerObject.Ref.Base.Health}");

        }
    }
}
